import React,{Component} from 'react'
import { Input } from 'antd';
import { Button } from 'antd';
import './login.css'
import {HttpUtil} from "bdjf_http";
import API from '../../http/api';
import { Link  } from "react-router-dom";


class Reg extends Component{

    state = {
        username:'',
        password:'',
        phone:'',
        regLoading:false
    }

//   constructor(props) {
//     super(props);
//     this.state = {
        
//     }
//   }




  render() {
    return (
        <div className="col-center">
            <div className="col form">
                <div>
                    <span className="title">注册</span>
                    <Link replace to="/">去登录</Link> 
                </div>
                <span className="input_label">用户名:</span>
                <Input allowClear  onChange={this.dataChange.bind(this,'username')} value={this.state.username} placeholder="请输入用户名" />
                
                <span className="input_label">密码:</span>
                <Input allowClear  onChange={this.dataChange.bind(this,'password')} value={this.state.password} placeholder="请输入密码" />
                
                <span className="input_label">手机号码:</span>
                <Input allowClear  onChange={this.dataChange.bind(this,'phone')} value={this.state.phone} placeholder="请输入手机号码" />
                
                <Button className="margin_item" type="primary" loading={this.state.loading} onClick={this.submit.bind(this)}>
                注册
                </Button>
            </div>
        </div>
    )
  }

  dataChange(key,e){
    this.setState({
        [key]:e.target.value
    })
  }

  submit(){
    const params = {
        ...this.state
    }
    this.setState({
        loading:true
    })
    HttpUtil.request(API.reg,params)
    .then(res=>{
        console.log(res)
        this.setState({
            loading:false
        })
    }).catch(err=>{
        console.log(err)
        this.setState({
            loading:false
        })
    })
  }

}

export default Reg;
